package models

import (
	"hospital-srv/basic/inits"
	"time"
)

type Problem struct {
	Id        uint32    `gorm:"column:id;type:int UNSIGNED;comment:问题Id;primaryKey;not null;" json:"id"`                                  // 问题Id
	UserId    uint32    `gorm:"column:user_id;type:int UNSIGNED;comment:用户Id;not null;default:0;" json:"user_id"`                         // 用户Id
	RoomId    int32     `gorm:"column:room_id;type:int;comment:会话室id;not null;" json:"room_id"`                                           // 会话室id
	Problem   string    `gorm:"column:problem;type:varchar(255);comment:提问问题;not null;" json:"problem"`                                   // 提问问题
	Reply     string    `gorm:"column:reply;type:text;comment:问题的回复;not null;" json:"reply"`                                              // 问题的回复
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);comment:创建时间;not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"` // 创建时间
	UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3);comment:修改时间;not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"` // 修改时间
	DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);comment:删除时间;default:NULL;" json:"deleted_at"`                          // 删除时间
}

func (p *Problem) TableName() string {
	return "problem"
}
func (p *Problem) CreateProblem() error {
	return inits.DB.Create(&p).Error
}
func (p *Problem) QuestionHistory() (history []Problem, err error) {
	err = inits.DB.Debug().Where("user_id = ? and room_id = ?", p.UserId, p.RoomId).Order("created_at desc").Limit(10).Find(&history).Error
	return
}
